HW1 Submission¶

Damanpreet Singh¶

Andrew ID: damanprs¶

q1 - Affine Rectification¶

For the q1, the algorithm used is as follows:

  • Select points on the image, to create set of parallel lines
  • Project these points into projective space, by appending 1 at the end of each
  • Generate lines by using the formula $ L = \overrightarrow{p1} \times \overrightarrow{p2} $
  • Generate point at infinty using the parallel lines, as $p_{1inf} = \overrightarrow{L1}\times\overrightarrow{L2}$, similarly for $p_{2inf}$
  • Generate line at infinty as, $l_{inf} = \overrightarrow{p_{1inf}} \times \overrightarrow{p_{2inf}}$
  • As for affine rectification, the homography matrix is, $H = \begin{bmatrix}1&0&0\\0&1&0\\l_1&l_2&1\end{bmatrix} $, we solve the equation of $H^{-T}l_{inf} = \begin{bmatrix}0\\0\\1\end{bmatrix}$
  • This leads to a solution of $l_1 = a_2 , l_2 = a_1$, where $l_{inf} = \begin{bmatrix}a_1\\a_2\\1\end{bmatrix}$

Results¶

tiles5¶

Input Image Annotated parallel lines Affine-Rectified Image
tiles5.JPG tiles5.jpg tile5.jpg
Line Before After
Green 0.933045 0.999662
Blue 0.999998 0.999997

tiles4¶

Input Image Annotated parallel lines Affine-Rectified Image
tiles4.jpg tile4.jpg tile4.jpg
Line Before After
Green 0.9802158 0.999982
Blue 0.999894 0.9999371

tiles6¶

Input Image Annotated parallel lines Affine-Rectified Image
tiles6.jpg tiles6.jpg tiles6.jpg
Line Before After
Green 0.999890 0.999768
Blue 0.9995473 0.9999913

calib1 (Calibration board)¶

Input Image Annotated parallel lines Affine-Rectified Image
calib1.jpg calib1.jpg calib1.jpg
Line Before After
Green 0.97703 1.0
Blue 0.999798 0.999833

res_building (Residential Building)¶

Input Image Annotated parallel lines Affine-Rectified Image
Screenshot from 2022-10-02 02-31-45.png res_building.jpg res_building.jpg
Line Before After
Green 0.999358 0.9990105
Blue 0.998932 0.9997795

q2 - Metric Rectification¶

For q2, the algorithm used is as follows:

  • Two sets of perpendicular lines are constructed using the same method as q1
  • The general shape of a line conic for an affine transformed image is $C_{\infty}^* = \begin{bmatrix} a&b&0\\b&c&0\\0&0& 0\end{bmatrix}$
  • Using a set of perpendicular lines, we know $l C_{\infty}^* m = 0$, we can construct a system of equations as $Ac=0$ , to extract $a,b,c$
  • These values are extracted using SVD
  • We need to compute an $H$, such that image.png
  • This is accomplished using SVD , as $ C_{\infty}^* = UDU^T $
  • Here, final H is calculated as, $H = \begin{bmatrix} \sqrt{\sigma_1^{-1}} & 0&0 \\ 0&\sqrt{\sigma_2^{-1}}&0\\0&0&1 \end{bmatrix}U^T$
  • So, the whole algorithm invloves two SVDs

Results¶

tiles5¶

Input Image Annotated parallel lines on affine image Metric-Rectified Image
tiles5.JPG tiles5_metric.jpg tiles5_metric.jpg
Line Before After
Green -0.195470 -0.0054723
Blue 0.0847146 0.0108689

tiles4¶

Input Image Annotated parallel lines on affine image Metric-Rectified Image
tiles4.jpg tile4_metrc.jpg tile4_metrc.jpg
Line Before After
Green 0.3796108 0.1708844
Blue 0.35701868 0.203533

tiles6¶

Input Image Annotated parallel lines on affine image Metric-Rectified Image
tiles6.jpg tiles6_metric.jpg tiles6_metric.jpg
Line Before After
Green 0.09290548 0.14334456
Blue 0.106657065 -0.15170103

q3 - Planar Homography¶

For q3, the algorithm used is:

  • Take 4 corner points of the first image
  • Take 4 corner points in the second image, on the positon you want to warp the first image
  • As we know, $Hp_1 \times p_2 =0$, we develop a $2n\times9$ matrix $A$, as

    image.png

  • This gives rise to a system of equation $Ah = 0$, wher $h$ is the fllattened homegraphy matrix $H$

  • The value is calculated using SVD
  • The first image is warped using the $\textit{MyWarp}$ function
  • The warped image is then copied into a bigger image, to fit the size of the second image
  • The area where the warped image is to be overlayed in the second image, is cleared
  • This clearing is done by detting co-ordinates of non-zero pixels in the warped image and putting those to $0$ in second image
  • Finally, the warped image is overlaid onto the second image, using $\textit{cv2.add()}$

Results¶

Normal Image Perspective Image Annotated corners in perspective image Warped and overlaid image
desk-normal.png desk-perspective.png q3_annotations.jpg q3_final.jpg

Late days¶

two.png